package me.xiaosiqi.syt.common.exception;


import lombok.extern.slf4j.Slf4j;
import me.xiaosiqi.syt.common.result.Result;
import me.xiaosiqi.syt.common.result.ResultCodeEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        log.error("出现异常：{}",e.getMessage(),e);
        return Result.fail(null, ResultCodeEnum.SERVICE_ERROR);
    }

    @ExceptionHandler(HospitalException.class)
    @ResponseBody
    public Result error(HospitalException e) {
        log.error("出现异常：{}",e.getMessage(),e);
        return Result.fail(null, e.getResultCodeEnum());
    }
}
